package com.hospital.controller;

import com.hospital.domain.pojo.Ward;
import com.hospital.domain.utils.Result;
import com.hospital.service.WardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/ward")
@CrossOrigin
public class WardController {

    @Autowired
    private WardService wardService;

    /**
     * 获取所有病房
     */
    @GetMapping("/query")
    public Result<List<Ward>> getAllWards() {
        return wardService.getAllWards();
    }

    /**
     * 根据科室获取病房
     */
    @GetMapping("/department/{depId}")
    public Result<List<Ward>> getWardsByDepartment(@PathVariable Integer depId) {
        return wardService.getWardsByDepartment(depId);
    }

    /**
     * 根据类型获取可用病房
     */
    @GetMapping("/available/{wType}")
    public Result<List<Ward>> getAvailableWardsByType(@PathVariable String wType) {
        return wardService.getAvailableWardsByType(wType);
    }

    /**
     * 获取病房详情
     */
    @GetMapping("/info/{wId}")
    public Result<Ward> getWardById(@PathVariable Integer wId) {
        return wardService.getWardById(wId);
    }

    /**
     * 更新病房可用床位数
     */
    @PutMapping("/update/{wId}/beds/{availableBeds}")
    public Result<String> updateWardAvailability(@PathVariable Integer wId, @PathVariable Integer availableBeds) {
        return wardService.updateWardAvailability(wId, availableBeds);
    }
}
